
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>添加面 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.2">
        
        
        
    
    <link rel="stylesheet" href="gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-prism/prism.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-theme-vuejs/vue.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="CustomCIrcle.html" />

    
    <link rel="prev" href="addLine.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="./">
            
                <a href="./">
            
                    
                    文档信息
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="build.html">
            
                <a href="build.html">
            
                    
                    项目构建
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="link.html">
            
                <a href="link.html">
            
                    
                    安装
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" >
            
                <span>
            
                    
                    基础使用
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="initMap.html">
            
                <a href="initMap.html">
            
                    
                    初始化地图
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="loadJXMap.html">
            
                <a href="loadJXMap.html">
            
                    
                    加载江西地图
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="LayerSwitcher.html">
            
                <a href="LayerSwitcher.html">
            
                    
                    底图切换
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="addPoints.html">
            
                <a href="addPoints.html">
            
                    
                    添加点
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="addLine.html">
            
                <a href="addLine.html">
            
                    
                    添加线
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.4.6" data-path="addPolygon.html">
            
                <a href="addPolygon.html">
            
                    
                    添加面
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7" data-path="CustomCIrcle.html">

                <a href="CustomCIrcle.html">


                    周边搜索圆

                </a>



        </li>


            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" >
            
                <span>
            
                    
                    进阶
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="CoordsTransform.html">
            
                <a href="CoordsTransform.html">
            
                    
                    坐标转换
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" >
            
                <span>
            
                    
                    类说明
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="class.html">
            
                <a href="class.html">
            
                    
                    map
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="." >添加面</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x6DFB;&#x52A0;&#x70B9;&#x8981;&#x7D20;">&#x6DFB;&#x52A0;&#x70B9;&#x8981;&#x7D20;</h1>
<blockquote>
<ul>
<li>&#x5730;&#x56FE;&#x5FC5;&#x987B;&#x521D;&#x59CB;&#x5316; <code>var Maps = new HMap.map(&apos;div&apos;, {}&apos;)</code></li>
</ul>
</blockquote>
<h2 id="examples">Examples</h2>
<p><a href="../../example/addPolygons.html">&#x8981;&#x7D20;&#x9762;&#x6DFB;&#x52A0;&#x5B9E;&#x4F8B;</a></p>
<p>&lt;!DOCTYPE html&gt;</p>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>&#x6D4B;&#x8BD5;&#x6DFB;&#x52A0;&#x9762;</title>
  <link rel="stylesheet" href="./lib/map/HMap.css" type="text/css">
  <script src="./lib/map/HMap.js"></script>
</head>
<body>
<button onclick="addPolygon()">&#x6DFB;&#x52A0;&#x9762;</button>
<button onclick="addPolygons()">&#x6DFB;&#x52A0;&#x591A;&#x9762;</button>
<button onclick="removePolygonById()">&#x901A;&#x8FC7;ID&#x79FB;&#x9664;&#x6807;&#x7ED8;&#x9762;</button>
<button onclick="removePolygonByLayerName()">&#x901A;&#x8FC7;LayerName&#x79FB;&#x9664;&#x6807;&#x7ED8;&#x9762;</button>
<div id="map"></div>
<script src="./lib/axios/axios.js"></script>
<script type="text/javascript">
  var cor = [
    {
      "level": 0,
      "resolution": 0.010986328383069278,
      "scale": 4617150
    },
    {
      "level": 1,
      "resolution": 0.005493164191534639,
      "scale": 2308575
    },
    {
      "level": 2,
      "resolution": 0.0027465809060368165,
      "scale": 1154287
    },
    {
      "level": 3,
      "resolution": 0.0013732916427489112,
      "scale": 577144
    },
    {
      "level": 4,
      "resolution": 6.866458213744556E-4,
      "scale": 288572
    },
    {
      "level": 5,
      "resolution": 3.433229106872278E-4,
      "scale": 144286
    },
    {
      "level": 6,
      "resolution": 1.716614553436139E-4,
      "scale": 72143
    },
    {
      "level": 7,
      "resolution": 8.582953794130404E-5,
      "scale": 36071
    },
    {
      "level": 8,
      "resolution": 4.291595870115493E-5,
      "scale": 18036
    },
    {
      "level": 9,
      "resolution": 2.1457979350577466E-5,
      "scale": 9018
    },
    {
      "level": 10,
      "resolution": 1.0728989675288733E-5,
      "scale": 4509
    },
    {
      "level": 11,
      "resolution": 5.363305107141452E-6,
      "scale": 2254
    },
    {
      "level": 12,
      "resolution": 2.681652553570726E-6,
      "scale": 1127
    }
  ];
  var resolutions = [];
  for (var i = 0; i < cor.length; i++) {
    resolutions.push(cor[i].resolution);
  }
  var Maps = new HMap.Map();
  Maps.initMap('map', {
    interactions: {
      altShiftDragRotate: true,
      doubleClickZoom: true,
      keyboard: true,
      mouseWheelZoom: true,
      shiftDragZoom: true,
      dragPan: true,
      pinchRotate: true,
      pinchZoom: true,
      zoomDelta: 1, // 缩放增量（默认一级）
      zoomDuration: 500 // 缩放持续时间
    },
    controls: {
      attribution: true,
      attributionOptions: {
        className: 'ol-attribution', // Default
        target: 'attributionTarget',
      },
      rotate: true,
      rotateOptions: {
        className: 'ol-rotate', // Default
        target: 'rotateTarget',
      },
      zoom: true,
      zoomOptions: {
        className: 'ol-zoom', // Default
        target: 'zoomTarget',
      },
      overViewMapVisible: false,
      scaleLineVisible: true
    },
    view: {
      center: [115.92466595234826, 27.428038204473552],
      resolutions: resolutions,
      fullExtent: [109.72859368643232, 24.010266905347684, 121.13105988819079, 30.76693489432357],
      tileSize: 256,
      origin: [-400, 399.9999999999998],
      enableRotation: true, // 是否允许旋转
      projection: 'EPSG:4326',
      rotation: 0,
      zoom: 1, // resolution
      zoomFactor: 2 // 用于约束分变率的缩放因子（高分辨率设备需要注意）
    },
    logo: {},
    baseLayers: [  // 不传时默认加载OSM地图。
      {
        layerName: 'vector',
        isDefault: true,
        layerType: 'TileXYZ',
        opaque: false, //图层是否不透明
        layerUrl: 'http://171.34.40.68:6080/arcgis/rest/services/JXMAP_2016_2/MapServer',
      }
    ]
  });
  console.log(Maps);
  function addPolygon () {
    // Make a request for a user with a given ID
    axios.get('./json/polygons.json')
      .then(function (response) {
        var polygon = response['data']['data']['features'][0];
        Maps.addPolygon(polygon, {
          layerName: 'test',
          zoomToExtent: true
        });
      })
      .catch(function (error) {
        console.log(error);
      });
  }
  function addPolygons () {
    axios.get('./json/polygons.json')
      .then(function (response) {
        var polygons = response['data']['data']['features'];
        Maps.addPolygons(polygons, {
          layerName: 'test',
          zoomToExtent: true
        });
      })
      .catch(function (error) {
        console.log(error);
      });
  }
  function removePolygonById () {
    Maps.removeFeatureById('ecc9f2ba-f899-4adb-a86a-284d81bf2911')
  }
  function removePolygonByLayerName () {
    Maps.removeFeatureByLayerName('test')
  }
</script>
</body>
</html>

<hr>
<pre class="language-"><code class="lang-html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>map<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
</code></pre>
<pre class="language-"><code class="lang-javascript"><span class="token keyword">function</span> addPolygon <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment" spellcheck="true">// Make a request for a user with a given ID</span>
    axios<span class="token punctuation">.</span><span class="token keyword">get</span><span class="token punctuation">(</span><span class="token string">&apos;./json/polygons.json&apos;</span><span class="token punctuation">)</span>
      <span class="token punctuation">.</span><span class="token function">then</span><span class="token punctuation">(</span><span class="token keyword">function</span> <span class="token punctuation">(</span>response<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">var</span> polygon <span class="token operator">=</span> response<span class="token punctuation">[</span><span class="token string">&apos;data&apos;</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token string">&apos;data&apos;</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token string">&apos;features&apos;</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
        Maps<span class="token punctuation">.</span><span class="token function">addPolygon</span><span class="token punctuation">(</span>polygon<span class="token punctuation">,</span> <span class="token punctuation">{</span>
          layerName<span class="token punctuation">:</span> <span class="token string">&apos;test&apos;</span><span class="token punctuation">,</span>
          zoomToExtent<span class="token punctuation">:</span> <span class="token boolean">true</span>
        <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token punctuation">}</span><span class="token punctuation">)</span>
      <span class="token punctuation">.</span><span class="token keyword">catch</span><span class="token punctuation">(</span><span class="token keyword">function</span> <span class="token punctuation">(</span>error<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>error<span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
  <span class="token keyword">function</span> addPolygons <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    axios<span class="token punctuation">.</span><span class="token keyword">get</span><span class="token punctuation">(</span><span class="token string">&apos;./json/polygons.json&apos;</span><span class="token punctuation">)</span>
      <span class="token punctuation">.</span><span class="token function">then</span><span class="token punctuation">(</span><span class="token keyword">function</span> <span class="token punctuation">(</span>response<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">var</span> polygons <span class="token operator">=</span> response<span class="token punctuation">[</span><span class="token string">&apos;data&apos;</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token string">&apos;data&apos;</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token string">&apos;features&apos;</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
        Maps<span class="token punctuation">.</span><span class="token function">addPolygons</span><span class="token punctuation">(</span>polygons<span class="token punctuation">,</span> <span class="token punctuation">{</span>
          layerName<span class="token punctuation">:</span> <span class="token string">&apos;test&apos;</span><span class="token punctuation">,</span>
          zoomToExtent<span class="token punctuation">:</span> <span class="token boolean">true</span>
        <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token punctuation">}</span><span class="token punctuation">)</span>
      <span class="token punctuation">.</span><span class="token keyword">catch</span><span class="token punctuation">(</span><span class="token keyword">function</span> <span class="token punctuation">(</span>error<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>error<span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
  <span class="token keyword">function</span> removePolygonById <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    Maps<span class="token punctuation">.</span><span class="token function">removeFeatureById</span><span class="token punctuation">(</span><span class="token string">&apos;ecc9f2ba-f899-4adb-a86a-284d81bf2911&apos;</span><span class="token punctuation">)</span>
  <span class="token punctuation">}</span>
  <span class="token keyword">function</span> removePolygonByLayerName <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    Maps<span class="token punctuation">.</span><span class="token function">removeFeatureByLayerName</span><span class="token punctuation">(</span><span class="token string">&apos;test&apos;</span><span class="token punctuation">)</span>
  <span class="token punctuation">}</span>
</code></pre>
<h3 id="parameters">Parameters:</h3>
<table>
<thead>
<tr>
<th style="text-align:left">Name</th>
<th style="text-align:left">Type</th>
<th style="text-align:left">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left"><code>polygon</code></td>
<td style="text-align:left"><code>Object</code></td>
<td style="text-align:left"><code>&#x6807;&#x51C6;&#x7A7A;&#x95F4;&#x8981;&#x7D20;</code></td>
</tr>
<tr>
<td style="text-align:left"><code>polygons</code></td>
<td style="text-align:left"><code>Array</code></td>
<td style="text-align:left"><code>&#x6807;&#x51C6;&#x7A7A;&#x95F4;&#x8981;&#x7D20;</code></td>
</tr>
<tr>
<td style="text-align:left"><code>params</code></td>
<td style="text-align:left"><code>Object</code></td>
<td style="text-align:left"><code>&#x76F8;&#x5173;&#x53C2;&#x6570;</code></td>
</tr>
</tbody>
</table>
<h3 id="methods">Methods</h3>
<h5 id="addpolygonpolygon-params"><code>addPolygon(polygon, params)</code></h5>
<blockquote>
<p>&#x6DFB;&#x52A0;&#x9762;</p>
</blockquote>
<h5 id="addpolygonspolygons-params"><code>addPolygons(polygons, params)</code></h5>
<blockquote>
<p>&#x6DFB;&#x52A0;&#x591A;&#x9762;</p>
</blockquote>
<h6 id="parameters">Parameters:</h6>
<table>
<thead>
<tr>
<th style="text-align:left">Name</th>
<th style="text-align:left">Type</th>
<th style="text-align:left">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left"><code>map</code></td>
<td style="text-align:left"><code>ol.Map</code></td>
<td style="text-align:left">&#x5730;&#x56FE;&#x5B9E;&#x4F8B;</td>
</tr>
</tbody>
</table>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="addLine.html" class="navigation navigation-prev " aria-label="Previous page: 添加线">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="CustomCIrcle.html" class="navigation navigation-next " aria-label="Next page: 周边搜索圆">
                    <i class="fa fa-angle-right"></i>
                </a>

            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"添加面","level":"1.4.6","depth":2,"next":{"title":"周边搜索圆","level":"1.4.7","depth":2,"path":"CustomCIrcle.md","ref":"CustomCIrcle.md","articles":[]},"previous":{"title":"添加线","level":"1.4.5","depth":2,"path":"addLine.md","ref":"addLine.md","articles":[]},"dir":"ltr"},"config":{"plugins":["edit-link","prism","theme-vuejs@git+https://github.com/pearofducks/gitbook-plugin-theme-vuejs.git","-fontsettings","-highlight","github","livereload"],"root":"./api","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"prism":{},"github":{"url":"https://github.com/smileFDD/HMap.git"},"livereload":{},"search":{},"theme-vuejs":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":false,"twitter":false,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"edit-link":{"label":"编辑此页","base":"https://github.com/smileFDD/HMap/tree/master/docs/api"},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"links":{"sharing":{"facebook":false,"twitter":false}},"gitbook":">3.0.0"},"file":{"path":"addPolygon.md","mtime":"2017-03-18T03:22:18.321Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2017-03-18T05:20:47.112Z"},"basePath":".","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="gitbook/gitbook.js"></script>
    <script src="gitbook/theme.js"></script>
    
        
        <script src="gitbook/gitbook-plugin-edit-link/plugin.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-github/plugin.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    

    </body>
</html>

